package com.xudow.app.dynamicstate_old.module.user;

import android.os.Bundle;
import android.support.annotation.NonNull;

import com.activeshare.edu.ucenter.models.base.Courses;
import com.activeshare.edu.ucenter.models.course.CourseWithOtherInfo;
import com.jude.beam.expansion.list.BeamListFragmentPresenter;
import com.xudow.app.dynamicstate_old.data.DynamicModel;
import com.xudow.app.dynamicstate_old.domain.entity.UserCourseWithOtherInfo;

/**
 * Created by ske on 2016/6/12.
 */
public class UserCoursePresenter extends BeamListFragmentPresenter<UserCourseFragment, UserCourseWithOtherInfo> {

    long userId;

    @Override
    protected void onCreateView(@NonNull UserCourseFragment view) {
        super.onCreateView(view);
        userId = getView().getArguments().getLong("userId");
        onRefresh();
    }

    @Override
    public void onRefresh() {
        DynamicModel.getInstance().getCourseForUser(userId, 1, 10)
                .doAfterTerminate(() -> setCurPage(2))
                .unsafeSubscribe(getRefreshSubscriber());
    }

    @Override
    public void onLoadMore() {
        DynamicModel.getInstance().getCourseForUser(userId, getCurPage() == 1 ? 2 : getCurPage(), 10)
                .unsafeSubscribe(getMoreSubscriber());
    }
}